﻿<Window x:Class="Com.CodePlex.SPC3.SPbAM.View.MainWindowView"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
		xmlns:localv="clr-namespace:Com.CodePlex.SPC3.SPbAM.View"
		xmlns:localvm="clr-namespace:Com.CodePlex.SPC3.SPbAM.ViewModel"
		xmlns:localc="clr-namespace:Com.CodePlex.SPC3.SPbAM.Controller"
		Title="{Binding Path=DisplayName}"
		WindowStartupLocation="CenterScreen"
		mc:Ignorable="d"
		d:DesignHeight="300" 
		d:DesignWidth="600">
	<Window.Resources>
		<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
		<localc:CommandReference x:Key="NewCommand" Command="{Binding NewCommand}" />
		<localc:CommandReference x:Key="OpenCommand" Command="{Binding OpenCommand}" />
		<localc:CommandReference x:Key="SaveCommand" Command="{Binding SaveCommand}" />
		<!-- dont use DataTemplate as state not stored between tabs
		<DataTemplate DataType="{x:Type localvm:ServerWorkspaceViewModel}">
			<localv:ServerWorkspaceView />
		</DataTemplate>
		-->
	</Window.Resources>
	<Window.InputBindings>
		<KeyBinding Modifiers="Control" Key="N" Command="{StaticResource NewCommand}"  />
		<KeyBinding Modifiers="Control" Key="O" Command="{StaticResource OpenCommand}" />
		<KeyBinding Gesture="CTRL+S" Command="{StaticResource SaveCommand}" />
	</Window.InputBindings>
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
			<RowDefinition Height="Auto"/>
		</Grid.RowDefinitions>
		<DockPanel Grid.Row="0" HorizontalAlignment="Stretch" Width="Auto" LastChildFill="False" AllowDrop="False" IsItemsHost="False">
			<Menu DockPanel.Dock="Top" KeyboardNavigation.TabNavigation="Cycle">
				<MenuItem Header="_File">
					<MenuItem Header="_New" Command="{Binding Path=NewCommand}" Icon="{StaticResource ImageNew}" />
					<MenuItem Header="_Open" Command="{Binding Path=OpenCommand}" Icon="{StaticResource ImageOpen}" />
					<MenuItem Header="_Save" Command="{Binding Path=SaveCommand}" Icon="{StaticResource ImageSave}" />
					<MenuItem Header="Save _As" Command="{Binding Path=SaveAsCommand}" Icon="{StaticResource ImageSaveAll}" />
					<MenuItem Header="_Close" Command="{Binding Path=CloseCommand}"  Icon="{StaticResource ImageCloseSmall}" />
					<localv:RecentFileList x:Name="RecentFileList" />
					<MenuItem Header="E_xit" Command="{Binding Path=ExitCommand}" />
				</MenuItem>
				<MenuItem Header="_Help" >
					<MenuItem Header="About" Command="{Binding Path=AboutCommand}" />
				</MenuItem>
			</Menu>
			<ToolBar DockPanel.Dock="Left">
				<Button Content="{StaticResource ImageNew}" ToolTip="New" Command="{Binding Path=NewCommand}" Style="{StaticResource toolbarButton}" />
				<Separator/>
				<Button Content="{StaticResource ImageOpen}" ToolTip="Open" Command="{Binding Path=OpenCommand}" Style="{StaticResource toolbarButton}" />
				<Separator/>
				<Button Content="{StaticResource ImageSave}" ToolTip="Save" Command="{Binding Path=SaveCommand}" Style="{StaticResource toolbarButton}" />
				<Button Content="{StaticResource ImageSaveAll}" ToolTip="Save All" Command="{Binding Path=SaveAllCommand}" Style="{StaticResource toolbarButton}" />
			</ToolBar>
			<ToolBar DockPanel.Dock="Right">
				<Button x:Name="closeMenuItem" Content="{StaticResource ImageCloseSmall}" ToolTip="Close" Command="{Binding Path=CloseCommand}" Style="{StaticResource toolbarButton}" />
			</ToolBar>		
		</DockPanel>
		<TabControl Grid.Row="1" ItemsSource="{Binding ServerWorkspaceViews}" SelectedIndex="{Binding ActiveServerWorkspace}" IsSynchronizedWithCurrentItem="True">
			<TabControl.ItemContainerStyle>
				<Style TargetType="TabItem">
					<Setter Property="Header" Value="{Binding}"/>
					<Setter Property="HeaderTemplate">
						<Setter.Value>
							<DataTemplate>
								<StackPanel Orientation="Horizontal">
									<TextBlock VerticalAlignment="Center">
											<TextBlock.Text>
												<MultiBinding Converter="{x:Static localv:ServerWorkspaceDisplayNameConverter.Default}">
													<Binding Path="DataContext.DisplayName"/>
													<Binding Path="DataContext.IsModified"/>
												</MultiBinding>
											</TextBlock.Text>
									</TextBlock>
									<Button Command="{Binding Command, ElementName=closeMenuItem}" Content="{StaticResource ImageCloseSmall}"
												Visibility="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}},Converter={StaticResource BooleanToVisibilityConverter}}"
												Width="16" Height="16" BorderThickness="0"
												MinWidth="0" MinHeight="0" Padding="0" Margin="7,0,0,0">
										<Button.Template>
											<ControlTemplate TargetType="{x:Type Button}">
												<ContentPresenter Margin="{TemplateBinding Control.Padding}" 
														HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
														VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
														SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
														ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
														RecognizesAccessKey="True"
														Content="{TemplateBinding ContentControl.Content}"/>
											</ControlTemplate>
										</Button.Template>
									</Button>
								</StackPanel>
							</DataTemplate>
						</Setter.Value>
					</Setter>
				</Style>
			</TabControl.ItemContainerStyle>
		</TabControl>
		<StatusBar Grid.Row="2" Height="28">
			<StatusBarItem Content="Ready" />
			<StatusBarItem HorizontalAlignment="Right">
				<ProgressBar 
						Width="100" 
						Height="16"
						Minimum="0" Maximum="100"
						Visibility="{Binding IsProgressBarVisible,Converter={StaticResource BooleanToVisibilityConverter}}"
						Value="{Binding Progress, Mode=OneWay}"/>
			</StatusBarItem>
		</StatusBar>
	</Grid>
</Window>
